package com.ruoyi.repairArea.service.impl;

import com.ruoyi.project.domain.HouseProjectT;
import com.ruoyi.project.domain.HouseRepairCheckT;
import com.ruoyi.repairArea.domain.HouseRepairAreaT;
import com.ruoyi.repairArea.mapper.HouseRepairAreaTMapper;
import com.ruoyi.repairArea.service.IHouseRepairAreaTService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 户资金修改Service业务层处理
 * 
 * @author tyq
 * @date 2023-05-24
 */
@Service
public class HouseRepairAreaTServiceImpl implements IHouseRepairAreaTService 
{
    @Autowired
    private HouseRepairAreaTMapper houseRepairAreaTMapper;

    /**
     * 查询户资金修改
     * 
     * @param doorId 户资金修改主键
     * @return 户资金修改
     */
    @Override
    public HouseRepairAreaT selectHouseRepairAreaTByDoorId(Long doorId)
    {
        return houseRepairAreaTMapper.selectHouseRepairAreaTByDoorId(doorId);
    }

    /**
     * 查询户资金修改列表
     * 
     * @param houseRepairAreaT 户资金修改
     * @return 户资金修改
     */
    @Override
    public List<HouseRepairAreaT> selectHouseRepairAreaTList(HouseRepairAreaT houseRepairAreaT)
    {
        return houseRepairAreaTMapper.selectHouseRepairAreaTList(houseRepairAreaT);
    }

    @Override
    public HouseRepairAreaT selectHouseRepairAreaSum(HouseRepairAreaT houseRepairAreaT)
    {
        return houseRepairAreaTMapper.selectHouseRepairAreaSum(houseRepairAreaT);
    }

    /**
     * 新增户资金修改
     * 
     * @param houseRepairAreaT 户资金修改
     * @return 结果
     */
    @Override
    public int insertHouseRepairAreaT(HouseRepairAreaT houseRepairAreaT)
    {
        return houseRepairAreaTMapper.insertHouseRepairAreaT(houseRepairAreaT);
    }

    /**
     * 修改户资金修改
     * 
     * @param  houseRepairAreaVO,  houseRepairCheckO, houseProjectT 户资金修改
     * @return 结果
     */
    @Override
    @Transactional
    public int updateHouseRepairAreaT(HouseRepairAreaT houseRepairAreaVO, HouseRepairCheckT houseRepairCheckO,HouseProjectT houseProjectT)
    {
        houseRepairAreaTMapper.insertRepairCheck(houseRepairCheckO);
        houseRepairAreaTMapper.updateRepairMoneyForCheck(houseRepairAreaVO);
        HouseRepairAreaT repairAreaVO=houseRepairAreaTMapper.sumNoMoney(houseProjectT);
        houseProjectT.setPayMoney(repairAreaVO.getPayMoney());
        return houseRepairAreaTMapper.updateProjectMoneyForCheck(houseProjectT);
    }

    /**
     * 批量删除户资金修改
     * 
     * @param doorIds 需要删除的户资金修改主键
     * @return 结果
     */
    @Override
    public int deleteHouseRepairAreaTByDoorIds(Long[] doorIds)
    {
        return houseRepairAreaTMapper.deleteHouseRepairAreaTByDoorIds(doorIds);
    }

    /**
     * 删除户资金修改信息
     * 
     * @param doorId 户资金修改主键
     * @return 结果
     */
    @Override
    public int deleteHouseRepairAreaTByDoorId(Long doorId)
    {
        return houseRepairAreaTMapper.deleteHouseRepairAreaTByDoorId(doorId);
    }

    /**
     * 核算维修项目
     *
     * @param projectVO,repairListTemp 核算维修项目主键
     * @return 结果
     */
    @Transactional
    @Override
    public int updateProjectAndRepair(HouseProjectT projectVO, List<HouseRepairAreaT> repairListTemp)
    {
        for(HouseRepairAreaT vo:repairListTemp){
            if(vo.getRepairMoney()==0){
                vo.setRepairMoney(0d);
            }
            houseRepairAreaTMapper.updateRepair(vo);
        }
        HouseRepairAreaT projectTemp = new HouseRepairAreaT();
        projectTemp=houseRepairAreaTMapper.sumNoMoney(projectVO);
        projectVO.setNoMoney(projectTemp.getNoMoney());
        return houseRepairAreaTMapper.updateProjectForTrueMoney(projectVO);
    }

    public HouseRepairAreaT selectHouseProjectTByProjectId(HouseRepairAreaT houseRepairAreaT)
    {
        return houseRepairAreaTMapper.selectHouseProjectTByProjectId(houseRepairAreaT);
    }

    public HouseRepairAreaT getRepairDetail(HouseRepairAreaT houseRepairAreaT)
    {
        return houseRepairAreaTMapper.getRepairDetail(houseRepairAreaT);
    }

}
